package com.yoomiito.app.interf;

import android.content.Context;
import android.widget.LinearLayout;

import com.yoomiito.app.base.BaseActivity;
import com.yoomiito.app.model.bean.GoodsDetail;
import com.yoomiito.app.net.YmApi;
import com.yoomiito.app.utils.AllCode;
import com.yoomiito.app.utils.AllUtils;
import com.yoomiito.app.utils.LoginUtils;

import cn.droidlover.xdroidmvp.net.ApiException;
import cn.droidlover.xdroidmvp.net.ApiSubscriber;
import cn.droidlover.xdroidmvp.net.BaseModel;
import cn.droidlover.xdroidmvp.net.XApi;
import io.reactivex.Flowable;

public abstract class BaseBottomBar extends LinearLayout {
    public Context mContext;
    public boolean mLogin;
    public GoodsDetail mGoodsDetail;
    private BottomBarListener mBottomBarListener;
    public BaseBottomBar(Context context,boolean isLogin) {
        super(context);
        mContext = context;
        mLogin = isLogin;
    }

    public void dispatchEvent(boolean share, boolean clickLeft, boolean clickRight) {
        if (mBottomBarListener!=null)mBottomBarListener.onClick(share, clickLeft, clickRight);
    }

    public void addBottomBarListener(BottomBarListener bottomBarListener) {
        mBottomBarListener = bottomBarListener;
    }

    public void updateInfo(GoodsDetail detail){
        this.mGoodsDetail = detail;
    }

    public boolean checkClick() {
        if (AllUtils.isFastClick()) {
            return false;
        }
        if (!mLogin) {
//            AllUtils.toLogin((BaseActivity) mContext, AllCode.LoginIn);
            LoginUtils.INSTANCE.toOneKeyLogin((BaseActivity) mContext);
            return false;
        }
        return true;
    }

    public Flowable<BaseModel> canBuy(String productId){
        return YmApi.getYmService()
                .canBuy(productId)
                .compose(((BaseActivity)mContext).bindToLifecycle())
                .compose(XApi.getApiTransformerNoData())
                .compose(XApi.getScheduler());
    }

    //用于部分UI不显示
    public void noShow(){

    }

}
